<?php echo $this->Html->script('usuario'); ?>
<form>
    <fieldset>
        <?php
        $r = 0;
        ?>
        <table width="98%" border="0" cellspacing="0" cellpadding="2" id="informacaoBasica">
            <thead>
            <th colspan="3">
                <b>INFORMAÇÕES BÁSICAS</b>
            </th>
            <th style="text-align: right;">
                <img src="/siscel/img/bt_apagar.gif" id="" />
                <img src="/siscel/img/bt_lapis.gif" id="" />
            </th>
            </thead>
            <tr>
                <td colspan="2" >
                    <?php echo $this->Form->input('Usuario.NM_AUT', array('type' => 'text', 'label' => 'Nome', 'id' => 'txtNome', 'class' => 'campoAlfa', 'size' => "30", 'maxlength' => "120", "value" => $usuario['Usuario']['NM_AUT'], 'readonly' => TRUE)); ?>
                </td>
                <td width="25%">
                    <?php echo $this->Form->input('Usuario.CD_LOGIN', array('type' => 'text', 'label' => 'CPF', 'id' => 'txtCDLOGIN', 'class' => 'campoCPF', 'size' => "20", 'maxlength' => "14", "value" => $usuario['Usuario']['CD_LOGIN'], 'readonly' => TRUE)); ?>
                </td>
                <td width="25%">
                    <?php $sexo = ($usuario['Usuario']['SEXO'] == 'M') ? 'Masculino' : ($usuario['Usuario']['SEXO'] == 'F') ? 'Feminino' : 'Não Informado'; ?>
                    <?php echo $this->Form->input('Usuario.SEXO', array('type' => 'text', 'label' => 'Sexo', 'id' => 'txtSexo', 'value' => $sexo, 'readonly' => TRUE)); ?>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <?php echo $this->Form->input('Usuario.DS_EMAIL', array('type' => 'email', 'label' => 'Email principal', 'id' => 'txtEmailPrincipal', 'class' => 'campoEmail', 'size' => "30", 'maxlength' => "120", "value" => $usuario['Usuario']['DS_EMAIL'], 'readonly' => TRUE)); ?>
                </td>
                <td colspan="2">
                    <?php echo $this->Form->input('Usuario.DS_EMAIL_SEC', array('type' => 'email', 'label' => 'Email secundario', 'id' => 'txtEmailSecundario', 'class' => 'campoEmail', 'size' => "30", 'maxlength' => "120", "value" => $usuario['Usuario']['DS_EMAIL_SEC'], 'readonly' => TRUE)); ?>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <?php // echo $this->Form->input('Usuario.TP_USU', array('type' => 'select', 'label' => 'Tipo', 'id' => 'slUsuario', 'options' => $arrUsuario)); ?>
                </td>
                <td>
                    <?php // echo $this->Form->input('Usuario.DS_UNIDADE', array('type' => 'email', 'label' => '&nbsp; ', 'id' => 'DS_UNIDADE', 'class' => 'campoEmail')); ?>
                </td>
                <td>
                    <?php // echo '<pre>'; var_dump($_SESSION["usuario"]["Usuario"]["CD_LOGIN"] == $usuario['Usuario']['CD_LOGIN']); exit; ?>
                    <?php if ($_SESSION["usuario"]["Usuario"]["CD_LOGIN"] == $usuario['Usuario']['CD_LOGIN']): ?>
                        <a id="trocarSenha" href="#this" onclick="javascript:modelTrocaSenha();">Trocar Senha</a>
                    <?php endif; ?>
                </td>
            </tr>
        </table>
    </fieldset>

    <fieldset>
        <table width="98%" border="0" cellspacing="0" cellpadding="2">
            <thead>
            <th colspan="5"><b>UNIDADES VINCULADAS</b></th>
            </thead>
            <?php
            $r = 0;
            ?>
            <?php if (count($usuario['INSTITUICAO'])): ?>
                <?php foreach ($usuario['INSTITUICAO'][0] as $unidade): ?>
                    <tr>
                        <td style="width: 2%;"><input type="checkbox" checked="checked" /></td>
                        <td>Nome: <?php echo $unidade['NM_INST'] ?></td>
                        <td>Nome Curto: <?php echo $unidade['NM_INST_CURTO'] ?></td>
                        <td>Cargo: <?php 'UF' // echo $usuario['INSTITUICAO'][0]["SERVICO"]['DS_SERVICO']        ?></td>
                        <td>Função: <?php 'Cidade' // echo $usuario['INSTITUICAO']['']       ?></td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </table>
    </fieldset>

    <fieldset>
        <table width="98%" border="0" cellspacing="0" cellpadding="2">
            <thead>
            <th colspan="3"><b>PERFIL</b></th>
            </thead>
            <?php $permissions = array(); 
            if (count($usuario['PERFIL'])): ?>
                <?php foreach ($usuario['PERFIL'] as $perfil): ?>
                    <?php foreach ($perfil as $key => $value): ?>
                        <?php if ($key == 'Perfil'): ?>
                            <tr>
                                <?php $situacao = ( isset($usuario["RelacionamentoAutoPerfilInst"][0]["CO_PERFIL"]) && $usuario["RelacionamentoAutoPerfilInst"][0]["CO_PERFIL"] == $value["CO_PERFIL"]) ? 'TRUE' : 'FALSE' ; ?>
                                <td style="width: 3%;"><input type="checkbox" <?php echo ($situacao == 'TRUE') ? ' checked="checked" ' : NULL ?>  onclick="javascript:vinculaPefilUsuario('<?php echo $usuario['Usuario']['CD_LOGIN'] ?>',  '<?php echo $value["CO_PERFIL"] ?>', '<?php echo $situacao ?>', '<?php echo !empty ($usuario["RelacionamentoAutoPerfilInst"][0]["CD_INST_LAB"]) ? $usuario["RelacionamentoAutoPerfilInst"][0]["CD_INST_LAB"] : '' ?>');"/></td>
                                <td><?php echo $value["NO_PERFIL"] ?></td>
                                <td><?php echo ($perfil['PERMISSAO']["DS_PERMISSAO"] ) ? ++$r . ' . ' . $perfil['PERMISSAO']["DS_PERMISSAO"] : NULL ?></td>
                            </tr>
                        <?php endif; ?>
                    <?php endforeach; ?>
                <?php endforeach; ?>
            <?php endif; ?>
        </table>
    </fieldset>

    <fieldset>
        <table width="98%" border="0" cellspacing="0" cellpadding="2">
            <thead>
            <th><b>MENSAGENS</b></th>
            </thead>
            <?php if (count($usuario['MENSAGEM'])): ?>
                <?php foreach ($usuario['MENSAGEM'] as $mensagem): ?>
                    <tr>
                        <td>DATA/HORA</td>
                        <td> MENSAGEM: </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </table>
    </fieldset>
</form>
<div id="modalTrocaSenha" title="Alterar Senha" style="display: none;">
    <div>
        <table>
            <tr>
                <td>
                    <?php echo $this->Form->input('DS_SENHA_ANTERIOR', array('type' => 'password', 'label' => 'Senha Anterior', 'id' => 'DS_SENHA_ANTERIOR', 'maxlength' => "60")); ?>
                </td>
            </tr>
            <tr>
                <td>
                    <?php echo $this->Form->input('DS_SENHA', array('type' => 'password', 'label' => 'Nova Senha', 'id' => 'DS_SENHA', 'maxlength' => "60")); ?>
                </td>
            </tr>
            <tr>
                <td>
                    <?php echo $this->Form->input('DS_SENHA_CONF', array('type' => 'password', 'label' => 'Confirmar Nova Senha', 'id' => 'DS_SENHA_CONF', 'maxlength' => "60")); ?>
                </td>
            </tr>
        </table>
    </div>
</div>